﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace FileConvert.AsposeOper
{
    public class PPTFile
    {
        public PPTFile(string fromFile, string toFile)
        {
            _formFile = fromFile;
            _toFile = toFile;
            AsposeRegister.Register_PPT();
            doc = new Aspose.Slides.Presentation(_formFile);
        }
        ~PPTFile()
        {
            doc.Dispose();
        }
        Aspose.Slides.Presentation doc;
        private string _formFile = "";
        private string _toFile = "";
        public void ConvertToPdf()
        {          
            doc.Save(_toFile, Aspose.Slides.Export.SaveFormat.Pdf);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void ConvertToXPS()
        {  
            doc.Save(_toFile, Aspose.Slides.Export.SaveFormat.Xps);
        }


        public void ConvertToHTML()
        { 
            doc.Save(_toFile, Aspose.Slides.Export.SaveFormat.Html);
        }

        /// <summary>
        /// 每个slide转换成一个svg
        /// </summary>
        /// <returns></returns>
        public void ConvertSingleSlideSVG()
        {
            int i = 1;
            foreach (var item in doc.Slides)
            {
                Aspose.Slides.Presentation temp = new Aspose.Slides.Presentation();
                temp.SlideSize.SetSize(doc.SlideSize.Size.Width, doc.SlideSize.Size.Height, Aspose.Slides.SlideSizeScaleType.DoNotScale);
                temp.SlideSize.Orientation = doc.SlideSize.Orientation;
                temp.Slides.RemoveAt(0);
                temp.Slides.AddClone(item);
                Stream stream = new MemoryStream();
                temp.Save(stream, Aspose.Slides.Export.SaveFormat.Pdf);

                if (Aspose.Pdf.Document.IsLicensed == false)
                {
                    AsposeRegister.Register_Pdf();
                }
                Aspose.Pdf.Document temppdf = new Aspose.Pdf.Document(stream);
                temppdf.Save(string.Format(@"{0}\{1}.svg", _toFile, i.ToString("0000")), Aspose.Pdf.SaveFormat.Svg);
                i = i + 1;
            }
        }
    }
}
